/**
 * @param {number} n
 * @return {boolean}
 */
var isPowerOfThree = function(n) {
    let bit = n.toString(3);
    return n === Math.pow(3,bit.length-1);
};

console.log(isPowerOfThree(2));